﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbMovieReviewsTest and is intended
    ///     to contain all TmdbMovieReviewsTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbMovieReviewsTest
    {
        /// <summary>
        ///     A test for TmdbMovieReviews Constructor
        /// </summary>
        [TestMethod]
        public void TmdbMovieReviewsConstructorTest()
        {
            var target = new TmdbMovieReviews();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for Id
        /// </summary>
        [TestMethod]
        public void IdTest()
        {
            var target = new TmdbMovieReviews();
            int expected = new Random().Next( 0, Int32.MaxValue );
            int actual;
            target.Id = expected;
            actual = target.Id;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Reviews
        /// </summary>
        [TestMethod]
        public void ReviewsTest()
        {
            var target = new TmdbMovieReviews();
            var expected = new List<TmdbReview>();
            target.Reviews = expected;
            var actual = target.Reviews;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem(@"..\..\TestData\movieReviews.json.txt")]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbMovieReviews();
            var jsonContent = File.ReadAllText("movieReviews.json.txt");
            var actual = await target.DeserializeJson<TmdbMovieReviews>(jsonContent);
            

            Assert.AreEqual(1, actual.PageNumber);
            Assert.AreEqual(1, actual.TotalResults);
            Assert.AreEqual(1, actual.TotalPages);
            Assert.AreEqual(1, actual.Reviews.Count);

            //Assert.IsTrue(false, "has to many properties!");
            Assert.AreEqual("51e86ad719c29529911b8687", actual.Reviews[0].Id);
            Assert.AreEqual("GeekMasher", actual.Reviews[0].Author);
            Assert.AreEqual(
                "First I want to say I liked this movie. I was surprised, \r\n I've been hearing bad reviews but I can't see big problem. The only issues was with the story. Apart from that the graphics where very good. The actors where okay (no major actors) and the baddies (no spoilers) where well thought out and graphically impressive (same for the robots).\r\n\r\nAll in all a good movie.",
                actual.Reviews[0].Content);
            Assert.AreEqual("http://j.mp/15qxoRI", actual.Reviews[0].Url);
        }
    }
}